<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard-polyfill/2.4.2/clipboard-polyfill.js"></script>
    <title>Document</title>
</head>

<body>
    <p id="p1"><b>He</b><b>llo</b> world!</p>
    <button id="btn">删除</button>
    <button id="extract">移除</button>
    <hr>
    <button id="copy">复制链接</button>
    <p id="tip"></p>
    <script>
        var btn = document.getElementById('btn')
        var extract = document.getElementById('extract')
        var p1 = document.getElementById("p1");
        var helloNode = p1.firstChild.firstChild;
        var worldNode = p1.lastChild;
        var range = document.createRange();
        range.setStart(helloNode, 2);
        range.setEnd(worldNode, 3);
        // console.log('range_>', range);
        btn.onclick = function del(params) {
            range.deleteContents();
        }
        extract.onclick = function ext(params) {
            var fragment = range.extractContents();
            console.log('range_>', fragment);
            p1.parentNode.appendChild(fragment);
        }

        // ================
        var copy = document.getElementById('copy');
        var tip = document.getElementById('tip');
        copy.onclick = function() {
            var href = 'https://www.baidu.com';
            clipboard.writeText(href)
                .then(() => {
                    tip.innerHTML = 'ok'
                })
                .catch(e => {
                    tip.innerHTML = e.toString();
                })
        }
    </script>
</body>

</html>